package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.apply.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.PurcOrderService;
import com.dom.domweb.utils.TradeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 采购订单控制器
 * @author xllei
 * @Date 2018-11-12
 */
@Slf4j
@RestController
@RequestMapping("/")
public class PurcOrderController {
    @Autowired
    PurcOrderService purcOrderService;

    @RequestMapping("/purc/getPurcOrderList")
    public TabPager getPurcOrderList(@RequestParam("limit")int limit, @RequestParam("page")int page, @RequestParam("exchStartDate") String exchStartDate,
                                     @RequestParam("exchEndDate") String exchEndDate, @RequestParam("deliStartDate") String deliStartDate,
                                     @RequestParam("deliEndDate") String deliEndDate, @RequestParam("makerId") String marketId, @RequestParam("stat") String stat,
                                 @RequestParam("storCode") String storCode, @RequestParam("suppCode") String suppCode, @RequestParam("verfyStat") String verfyStat){
        P039R request = new P039R();
        request.setPn(page);
        request.setPs(limit);
        request.setExchStartDate(exchStartDate);
        request.setExchEndDate(exchEndDate);
        request.setDeliStartDate(deliStartDate);
        request.setDeliEndDate(deliEndDate);
        request.setMakerId(marketId);
        request.setStat(stat);
        request.setStorCode(storCode);
        request.setSuppCode(suppCode);
        request.setVerfyStat(verfyStat);
        P039A response = purcOrderService.findPurcOrderList(request);
        return new TabPager(response.getOrderData(), response.getTotalNum());
    }

    @RequestMapping(value = "/purc/addPurcOrder", method = RequestMethod.POST)
    public RspModel addPurcOrder(@RequestBody P030R request) {
        TradeUtil.setHead(request);

        String orderId = purcOrderService.addPurcOrder(request);
        return new RspModel(orderId);
    }

    @RequestMapping(value = "/purc/order/getPurcOrderDetailList", method = RequestMethod.GET)
    public TabPager getPurcOrderDetailList(@RequestParam("orderId") Integer orderId){
        P049R request = new P049R();
        TradeUtil.setHead(request);
        request.setOrderId(orderId);

        P049A response = purcOrderService.findPurcOrderDetail(request);
        return new TabPager(response.getOrderDetailInfos(), response.getTotalNum());
    }

    @RequestMapping(value = "purc/editPurcOrder", method = RequestMethod.POST)
    public RspModel editPurcOrder(@RequestBody P032R request){
        TradeUtil.setHead(request);

        P032A response = purcOrderService.editPurcOrder(request);

        return new RspModel(response.getOrderId());
    }
}
